<template>
	<view class="fond-good-box flex f-d-c">
		<view class="form-item flex j-c-b m-b-30">
			<view class="left color-333 f-s-24">
				文字描述
			</view>
			<view class="right">
				<view class="box1 w-100 flex a-i-c j-c-b">
					<textarea name="" class="textarea-box f-s-26 color-333" v-model="content"></textarea>
				</view>
			</view>
		</view>
		<view class="form-item flex j-c-b">
			<view class="left color-333 f-s-24">
				上传图片
			</view>
			<view class="right">
				<view class="box2 w-100 flex f-d-c">
					<view class="w-100 flex f-w-w">
						<block v-for="(item, index) in images" :key="index">
							<upload-box :current="index" buttonType="circle" iconType="2" :src="item" @del="delImage" @success="uploadSuccess"></upload-box>
						</block>
						<upload-box current="" iconType="2" buttonType="circle" src="" @success="uploadSuccess"></upload-box>
					</view>
				</view>
			</view> 
		</view>
		<bottom-btn :positon="false" btnType="2" @click="requestData">确认发布</bottom-btn>
	</view>
</template>

<script>
	import uploadBox from "@/components/myComponents/uploadBox.vue"
	import bottomBtn from "@/components/myComponents/bottomBtn.vue"
	import {reditTo} from "@/nav.js"
	export default {
		name:"sellingCarsBox",
		components:{
			"upload-box":uploadBox,
			"bottom-btn":bottomBtn
		},
		data() {
			return {
				content:"",
				images:[],
				lng:0,
				lat:0,
				is_post:"",
				id:""
			};
		},
		mounted() {
			this.getLocationThis()
			let str = this.$store.state.page_tab_info
			let item = {}
			if(!!str){
				item = JSON.parse(str)
				this.id = item.id
				this.images = item.images
				this.content = item.content
			}
		},
		methods:{
			delImage(index){
				this.images.splice(index,1)
			},
			requestData(e){
				console.log(e)
				if(this.content === ""){
					uni.showToast({
						title:"请输入标题",
						icon:"none"
					})
					return
				}
				this.postSellingCar()
			},
			postSellingCar(){
				let that = this
				// return
				if(that.is_post !== ''){
					return
				}
				uni.showLoading({
					title:"提交中..."
				})
				that.is_post = '1'
				that.util.postRequest({
					url:"v1/content/socialize_edit",
					data:{
						content:that.content,
						images:that.images,
						lng:that.lng,
						lat:that.lat
					}
				}).then(res=>{
					uni.hideLoading()
					console.log(res)
					that.is_post=""
					// reditTo({url:'/pages/success/successPage'})
					uni.showToast({
						title:"待审核",
						duration:2500
					})
					// let timeout = setTimeout(()=>{
					// 	clearTimeout(timeout)
					// 	uni.navigateBack()
					// },2500)
				}).catch(e=>{
					uni.hideLoading()
				})
			},
			getLocationThis(){
				let that = this
				uni.showLoading({
					title:"定位中..."
				})
				that.$location.myGetLocation((res)=>{
					uni.hideLoading()
					that.lng = res.lng
					that.lat = res.lat
				},false)
			},
			uploadSuccess(e){
				let {index,url} = e
				if(index === ''){
					this.images.push(url)
				}else{
					this.images.splice(index,1,url)
				}
			},
		}
	}
</script>

<style lang="scss" scoped>
	.fond-good-box{
		width: 100%;
		border-radius: 20upx;
		background-color: #FFFFFF;
		padding: 30upx;
		.upload-form{}
		.form-item{
			width: 100%;
			padding: 0 16upx;
			min-height: 80upx;
			.right{
				width: 430upx;
				.box1{
					.input{
						width: 380upx;
					}
				}
				.box2{
					.title{
						margin-bottom: 26upx;
						line-height: 50upx;
					}
				}
			}
			.left{
				line-height: 50upx;
			}
		}
	}
	.textarea-box{
		width: 100%;
		height: 158upx;
		background: #F7F7F7;
		border-radius: 8upx;
		padding: 20upx;
	}
	.form-next-icon{
		width: 26upx;
		height: 26upx;
	}
	
</style>